<template>
  <div>
    <MyHeader title="购物车" bgc="pink" color="skyblue"></MyHeader>
    <div class="main">
      <MyGoods v-for="obj in list" :key="obj.id" :item="obj"></MyGoods>
    </div>
    <MyFooter @newAll="newall" :arr="list"></MyFooter>
  </div>
</template>

<script>
import MyHeader from "@/components/MyHeader";
import MyGoods from "@/components/MyGoods";
import MyFooter from "@/components/MyFooter";
export default {
  components: {
    MyHeader,
    MyGoods,
    MyFooter,
  },
  data() {
    return {
      list: [], // 所有商品数据
    };
  },
  created() {
    // 不必在自己引入axios变量, 而是直接使用全局属性$axios
    this.$axios({
      url: "/api/cart",
    }).then((res) => {
      // console.log(res);
      this.list = res.data.list;
    });
  },
  methods: {
    newall(boolean) {
      this.list.forEach((obj) => (obj.goods_state = boolean));
      // 把MyFooter内的全选状态true/false同步给所有小选框的关联属性上
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  padding-top: 45px;
  padding-bottom: 50px;
}
</style>
